package cn.wzx.controller;

import cn.wzx.entity.BookType;
import cn.wzx.respJson.RespJson;
import cn.wzx.service.BookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin // 允许跨域访问
@Controller
@RequestMapping("/api/adm/type")
public class BookTypeController {
    @Autowired
    BookTypeService bookTypeService;

    @ResponseBody
    @RequestMapping("/findAll")
    // 书本类型全查询
    public Map<String,Object> findAll(){
        return RespJson.pack(200,"OK",bookTypeService.findAll());
    }

    @ResponseBody
    @RequestMapping("/findById/{id}")
    // 根据ID查询书本类型
    public Map<String,Object> findById(@PathVariable("id") Integer id){
        return RespJson.pack(200,"",bookTypeService.findById(id));
    }

    @ResponseBody
    @RequestMapping("/add")
    // 添加类型
    public Map<String,Object> add(BookType bookType){
        bookTypeService.add(bookType.getId(),bookType.getType());
        return RespJson.pack(200,"添加成功",bookTypeService.findAll());
    }
}
